package com.jc.service.api;

import java.lang.reflect.ParameterizedType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;

import com.alibaba.fastjson.JSONObject;
import com.jc.ds.base.service.BaseServiceException;
import com.jc.service.api.order.add;

public abstract class BaseDual<T> {
	
	public Logger getLoger() {
		return LoggerFactory.getLogger(this.getClass());
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getData(JSONObject data) {
		Class <T> entityClass = (Class <T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; 
		try {
			return JSONObject.toJavaObject(data, entityClass);
			//如果data 为Object 格式,则用下面方法转换 zyf 2018.12.06
			//	return JSONObject.parseObject(JSONObject.toJSONString(data),entityClass);
		}catch(Exception e) {
			throw new BaseServiceException("data 业务数据转换出错,请检查你的业务数据是否符合文档!");
		}
	}
	
	public <T> T getData(String data,Class<T> clazz) {
		return JSONObject.parseObject(data,clazz);
	}
	
	
	public abstract ResponseEntity<?> dual(JSONObject data);

}
